import request from "@/utils/request";
enum API {
  // 获取角色分页列表的接口地址
  ROLELIST_URL = "/admin/acl/role/",
  // 新增角色的接口地址
  ADDROLE_URL = "/admin/acl/role/save",
  // 修改角色接口地址
  UPDATEROLE_URL = "/admin/acl/role/update",
  // 根据角色获取菜单的接口地址
  MENULIST_URL = "/admin/acl/permission/toAssign/",
  // 给角色分配权限的接口地址
  SETPERMISSION_URL = "/admin/acl/permission/doAssign/",
  // 删除职位的接口地址
  REMOVEROLE_URL = "/admin/acl/role/remove/",
}
// 获取角色分页列表的接口
export const reqRoleList = (page: number, limit: number, roleName: string) =>
  request.get<any, any>(
    API.ROLELIST_URL + `${page}/${limit}/?roleName=${roleName}`
  );
// 新增和修改角色的接口
export const reqAddOrUpdateRole = (data: any) => {
  if (data.id) {
    return request.put(API.UPDATEROLE_URL, data);
  } else {
    return request.post(API.ADDROLE_URL, data);
  }
};
// 根据角色获取菜单的接口
export const reqMenuList = (roleId: number) =>
  request.get<any, any>(API.MENULIST_URL + roleId);
// 给角色分配权限的接口
export const reqSetMission = (roleId: number, permissionId: number[]) =>
  request.post<any, any>(
    API.SETPERMISSION_URL + `?roleId=${roleId}&permissionId=${permissionId}`
  );
// 删除职位的接口
export const reqRemoveRole = (id: number) =>
  request.delete<any, any>(API.REMOVEROLE_URL + id);
